<template>
  <div class="user-add-main">
    <el-form ref="addForm" :model="jobs" clearable filterable label-width="90px">
      <el-form-item label="岗位名称:" prop="jobsName" :rules="addRules.jobsName">
        <el-input v-model="jobs.jobsName" />
      </el-form-item>
      <el-form-item label="岗位介绍:" prop="jobsIntroduce" :rules="addRules.jobsIntroduce">
        <el-input type="textarea" v-model="jobs.jobsIntroduce"  />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import jobsApi from '@/api/jobs'

export default {
  props: {
    // eslint-disable-next-line vue/require-prop-types
    jobs: {
      jobs: Object,
      default: null
    }
  },
  data() {
    return {
      addRules: {
        jobsName: [{ type: 'String', required: true, trigger: 'blur', validator: (rule, value, callback) => {
                if (value=="") {
                  callback(new Error('*岗位名称不能为空!'))
                } else if(value.length<2){
                  callback(new Error('*请输入正确岗位名称!'))
                } else {
                  this.$refs['addForm'].clearValidate(['jobsName']);
                  callback()
                }
              }
        }],
        jobsIntroduce: [{ type: 'String', required: true, trigger: 'blur', validator: (rule, value, callback) => {
                if (value=="") {
                  callback(new Error('*岗位介绍不能为空!'))
                } else {
                  this.$refs['addForm'].clearValidate(['jobsIntroduce']);
                  callback()
                }
              }
        }],
      }
    }
  },
  methods: {
    onSubmit() {
        this.$refs.addForm.validate(valid => {
        if (valid) {
          jobsApi.updateJob(this.jobs).then(res => {
            this.$message.success(res.data)
            this.$emit('closeDisplay')
            this.$emit('getPageList')
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
  .user-add-main{
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
